local joy__zhiyu = fk.CreateSkill {

  name = "joy__zhiyu",

  tags = {  },

}



joy__zhiyu:addEffect(fk.Damaged, {
  name = "joy__zhiyu",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(joy__zhiyu.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, joy__zhiyu.name)
    if not player.dead and not player:isKongcheng() then
      room:askForDiscard(player, 1, 1, false, joy__zhiyu.name, false)
    end
    local cards = table.simpleClone(player:getCardIds("h"))
    player:showCards(cards)
    if player.dead or not data.from or data.from.dead or data.from:getHandcardNum() <= player:getHandcardNum() then return end
    if table.every(cards, function(id) return #cards == 0 or Fk:getCardById(id).color == Fk:getCardById(cards[1]).color end) and
      room:askForSkillInvoke(player, joy__zhiyu.name, nil, "#joy__zhiyu-discard::"..data.from.id) then
      room:doIndicate(player.id, {data.from.id})
      local n = data.from:getHandcardNum() - player:getHandcardNum()
      room:askForDiscard(data.from, n, n, false, joy__zhiyu.name, false)
    end
  end,
})

return joy__zhiyu